<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Groups/classes/PhpFox_ComponentDelete.class.php, $Author:  $ */



/** Component for delete group
 * @version $Id: PhpFox_ComponentDelete.class.php 
 *  Max Kovrigovich
 * @package module.groups
 */
class PhpFox_Mod_Groups_ComponentDelete extends BaseComponent
{
    /** Processing method
     */
    function process()
    {
        //check permissions
        $oSecurityService = App::getModuleService('Account', 'Security');
		/* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
		$oSecurityService->checkPerm('groups', array('full')); 
        
        $oGroupsService = $this->_oModule->getService('Groups');
        /* @var $oGroupsService PhpFox_Mod_Groups_ServiceGroups */
        
        $oReq = &App::getRequest();
        /* @var $oReq Request */
        
        $oTpl = $this->_oModule->getTemplate();

        $iGroupId = $oReq->getInt('id', 0);
        $oUser = $this->getParam('user');

        if(!$iGroupId || !$oUser)
            return App::gotoUrl('groups');

        $bIsDeleted = false;
        $bIsOwner = $oGroupsService->isOwner($iGroupId, $oUser->aData['user']);
        $aGroupData = $oGroupsService->getGroupData($iGroupId);

        //not owner & not admin
        if(!$bIsOwner && !App::isStaff())
        {
            App::gotoUrl('groups');
        }

        //owner or admin    
        if($oReq->getAction() == 'delete' && ($bIsOwner || App::isStaff()))
        {
            $oGroupsService->deleteGroup($iGroupId);
            $bIsDeleted = true;
        }
        
        $oTpl->assign(array(
            'aGroupData' => $aGroupData,
            'isDeleted' => $bIsDeleted,
        ));
	        $sHtml = $oTpl->fetch('Delete.html');
        return $sHtml;
    }
}
?>